package com.cn.serverline.lineicp.produce.service.impl;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.serverline.lineicp.produce.entity.ProcessDescription;
import com.cn.serverline.lineicp.produce.entity.StepRequired;
import com.cn.serverline.lineicp.produce.entity.dto.GlueRecordingDto;
import com.cn.serverline.lineicp.produce.entity.dto.RoastRecordsDto;
import com.cn.serverline.lineicp.produce.entity.dto.SaveAssemblyTaskDto;
import com.cn.serverline.lineicp.produce.entity.dto.*;
import com.cn.serverline.lineicp.produce.entity.vo.*;
import com.cn.serverline.lineicp.produce.eums.ProduceEum;
import com.cn.serverline.lineicp.produce.mapper.ProcessDescriptionMapper;
import com.cn.serverline.lineicp.produce.service.IProcessDescriptionService;
import com.cn.serverline.lineicp.produce.service.IStepRequiredService;
import com.cn.serverline.lineicp.productionLine.entity.ProcessSteps;
import com.cn.serverline.lineicp.productionLine.mapper.ProcessStepsMapper;

import com.cn.serverline.lineicp.workshopPlan.entity.PlanLineAutomatic;
import com.cn.serverline.lineicp.workshopPlan.entity.PlanLineSchedule;
import com.cn.serverline.lineicp.workshopPlan.mapper.PlanLineAutomaticMapper;
import com.cn.serverline.lineicp.workshopPlan.mapper.PlanLineScheduleMapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.serverTechnology.craft.entity.StepsParameter;
import com.serverTechnology.craft.entity.StepsResourceType;
import com.serverTechnology.craft.mapper.StepsParameterMapper;
import com.serverTechnology.resource.entity.DeviceConfigEntity;
import com.serverTechnology.resource.entity.DeviceEntity;
import com.serverTechnology.resource.entity.DispositionEntity;
import com.serverTechnology.resource.mapper.DeviceConfigMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.serverTechnology.teamsGroups.constants.FixedNames.ONE;

/**
 * <p>
 * 生产执行工艺描述 服务实现类
 * </p>
 *
 * @author 王烁
 * @since 2024-08-12
 */
@Service
public class TeProcessDescriptionServiceImpl extends ServiceImpl<ProcessDescriptionMapper, ProcessDescription> implements IProcessDescriptionService {

    @Autowired
    private ProcessDescriptionMapper processDescriptionMapper;
    //工序工步表 Mapper 接口
    @Autowired
    private ProcessStepsMapper processStepsMapper;
    //工步所需 服务类
    @Autowired
    private IStepRequiredService stepRequiredService;
    //总装
    @Autowired
    private PlanLineAutomaticMapper planLineAutomaticMapper;
    //部装
    @Autowired
    private PlanLineScheduleMapper planLineScheduleMapper;
    //工步所需参数
    @Autowired
    private StepsParameterMapper stepsParameterMapper;
    @Autowired
    private DeviceConfigMapper deviceConfigMapper;

    public TeProcessDescriptionServiceImpl() {
    }

    /***
     * 1.通过工序查询出，工步的数量和工步ID  （这样可以知道每个工序有多少个工步，没个工步都需要保存一遍）
     * 2.批次号是2，工序是2 工步是2 那就是2*2*2
     *
     * 4步数和步数的设备
     *
     */
    @Override
    public void savegetAssemblyTask(SaveAssemblyTaskDto saveAssemblyTaskDto) {
        /**
         * 主要方法：处理并保存总装或部装任务的逻辑。
         * 根据任务的类型（总装或部装），检查是否有正在执行的任务。
         * 如果没有，则更新任务状态，并为每个任务生成相关的生产描述数据和所需参数，最后批量保存到数据库中。
         */

        // 提取常用变量
        String distinguish = saveAssemblyTaskDto.getDistinguish(); // 任务类型
        Long staterNumberInProgress = 2L; // 表示任务正在执行的状态编号
        Long automaticScheduleId = saveAssemblyTaskDto.getAutomaticScheduleId(); // 自动化调度的ID

        // 处理总装任务
        if ("ASSEMBLY".equals(distinguish)) {
            handleAssemblyTask(staterNumberInProgress, automaticScheduleId);
        }
        // 处理部装任务
        else if ("DIVISION".equals(distinguish)) {
            handleDivisionTask(staterNumberInProgress, automaticScheduleId);
        }

        // 获取与生产流程ID对应的工步ID列表
        List<Long> processStepsIds = processStepsMapper.selectList(
                new MPJLambdaWrapper<ProcessSteps>()
                        .select(ProcessSteps::getId)
                        .eq(ProcessSteps::getProductionProcessesId, saveAssemblyTaskDto.getProductionProcessesId())
        ).stream().map(ProcessSteps::getId).collect(Collectors.toList());

        // 准备生产描述的数据
        List<ProcessDescription> processDescriptions = prepareProcessDescriptions(saveAssemblyTaskDto, processStepsIds);
        if (!processDescriptions.isEmpty()) {
            // 批量保存生产描述
            this.saveBatch(processDescriptions);
        }

        // 查询工步所需的参数并构建映射
        Map<String, Map<Long, List<SaveStepRequiredVo>>> stepRequiredMaps = queryStepRequired(saveAssemblyTaskDto);

        // 准备并批量保存 StepRequired 对象
        List<StepRequired> stepRequiredList = prepareStepRequireds(processDescriptions, stepRequiredMaps);
        if (!stepRequiredList.isEmpty()) {
            stepRequiredService.saveBatch(stepRequiredList);
        }
    }

    /**
     * 处理总装任务：检查是否有正在执行的总装任务。
     * 如果有，则抛出异常，阻止重复下发任务；
     * 如果没有，则更新相应的总装任务状态为执行中。
     */
    private void handleAssemblyTask(Long staterNumberInProgress, Long automaticScheduleId) {
        // 查询当前是否有正在执行的总装任务
        Long count = planLineAutomaticMapper.selectCount(new LambdaQueryWrapper<PlanLineAutomatic>()
                .eq(PlanLineAutomatic::getStaterNumber, staterNumberInProgress));

        if (count > 0L) {
            // 如果有正在执行的总装任务，抛出异常
            throw new RuntimeException("总装任务正在执行中，请勿重复下发");
        } else {
            // 否则，更新总装任务的状态为执行中
            updatePlanLineAutomatic(staterNumberInProgress, automaticScheduleId);
        }
    }

    /**
     * 处理部装任务：检查是否有正在执行的部装任务。
     * 如果有，则抛出异常，阻止重复下发任务；
     * 如果没有，则更新相应的部装任务状态为执行中。
     */
    private void handleDivisionTask(Long staterNumberInProgress, Long automaticScheduleId) {
        // 查询当前是否有正在执行的部装任务
        Long count = planLineScheduleMapper.selectCount(new LambdaQueryWrapper<PlanLineSchedule>()
                .eq(PlanLineSchedule::getStaterNumber, staterNumberInProgress));
        if (count > 0L) {
            // 如果有正在执行的部装任务，抛出异常
            throw new RuntimeException("部装任务正在执行中，请勿重复下发");
        } else {
            // 否则，更新部装任务的状态为执行中
            updatePlanLineSchedule(staterNumberInProgress, automaticScheduleId);
        }
    }

    /**
     * 更新总装任务的状态为执行中。
     *
     * @param staterNumberInProgress 任务正在执行的状态编号
     * @param automaticScheduleId    要更新的总装任务ID
     */
    private void updatePlanLineAutomatic(Long staterNumberInProgress, Long automaticScheduleId) {
        PlanLineAutomatic planLineAutomatic = new PlanLineAutomatic();
        planLineAutomatic.setStaterNumber(staterNumberInProgress);
        planLineAutomaticMapper.update(planLineAutomatic,
                new LambdaQueryWrapper<PlanLineAutomatic>().eq(PlanLineAutomatic::getId, automaticScheduleId));
    }

    /**
     * 更新部装任务的状态为执行中。
     *
     * @param staterNumberInProgress 任务正在执行的状态编号
     * @param automaticScheduleId    要更新的部装任务ID
     */
    private void updatePlanLineSchedule(Long staterNumberInProgress, Long automaticScheduleId) {
        PlanLineSchedule planLineSchedule = new PlanLineSchedule();
        planLineSchedule.setStaterNumber(staterNumberInProgress);
        planLineScheduleMapper.update(planLineSchedule,
                new LambdaQueryWrapper<PlanLineSchedule>().eq(PlanLineSchedule::getId, automaticScheduleId));
    }

    /**
     * 准备生产描述数据：根据任务的计划数量和工步ID列表，
     * 生成一系列 ProcessDescription 对象，用于描述生产过程中的各个步骤和排序。
     *
     * @param saveAssemblyTaskDto 包含任务信息的数据传输对象
     * @param processStepsIds     工步ID列表
     * @return 包含所有生产描述的列表
     */
    private List<ProcessDescription> prepareProcessDescriptions(SaveAssemblyTaskDto saveAssemblyTaskDto, List<Long> processStepsIds) {
        List<ProcessDescription> processDescriptions = new ArrayList<>();
        // 生产流程ID
        Long productionProcessesId = saveAssemblyTaskDto.getProductionProcessesId();
        // 任务类型
        String distinguish = saveAssemblyTaskDto.getDistinguish();
        long sortOrder = 1; // 初始化排序序号
        // 遍历计划数量，构建 ProcessDescription 对象
        for (long i = 0L; i < saveAssemblyTaskDto.getPlanQuantity(); i++) {
            for (Long processStepsId : processStepsIds) {
                ProcessDescription processDescription = new ProcessDescription();
                processDescription.setProcessStepsId(processStepsId);
                processDescription.setState(2L); // 设置状态
                if ("DIVISION".equals(distinguish)) {
                    processDescription.setPartNumber(String.valueOf(i + 1));
                }
                processDescription.setSort(sortOrder++); // 设置排序
                processDescription.setProductionProcessesId(productionProcessesId);
                processDescription.setAutomaticScheduleId(saveAssemblyTaskDto.getAutomaticScheduleId());
                processDescription.setDistinguish(distinguish); // 设置任务类型
                processDescriptions.add(processDescription);
            }
        }
        return processDescriptions;
    }

    /**
     * 查询工步所需的参数：通过构建复杂的SQL查询，
     * 获取每个工步所需的设备和参数，并将结果按设备区分、按工步ID分组存储在映射中，
     * 便于后续操作。
     *
     * @param saveAssemblyTaskDto 包含任务信息的数据传输对象
     * @return 按设备区分的工步所需参数映射
     */
    private Map<String, Map<Long, List<SaveStepRequiredVo>>> queryStepRequired(SaveAssemblyTaskDto saveAssemblyTaskDto) {
        // 构建查询条件
        MPJLambdaWrapper<ProcessSteps> wrapper = new MPJLambdaWrapper<>();
        wrapper.selectAs(ProcessSteps::getId, SaveStepRequiredVo::getStepId)
                .selectAs(DeviceEntity::getId, SaveStepRequiredVo::getDeviceId)
                .selectAs(DispositionEntity::getId, SaveStepRequiredVo::getStepsParameterId)
                .select(StepsParameter::getNominalValue, StepsParameter::getMaxValue, StepsParameter::getMinValue)
                .select(StepsResourceType::getDeviceDistinguish)
                .innerJoin(StepsResourceType.class, StepsResourceType::getProcessStepsId, ProcessSteps::getId)
                .leftJoin(DeviceEntity.class, DeviceEntity::getId, StepsResourceType::getDeviceId)
                .leftJoin(StepsParameter.class, StepsParameter::getStepsResourceTypeId, StepsResourceType::getId)
                .leftJoin(DispositionEntity.class, DispositionEntity::getId, StepsParameter::getDispositionId)
                .eq(ProcessSteps::getProductionProcessesId, saveAssemblyTaskDto.getProductionProcessesId());
        // 执行查询并转换结果
        List<SaveStepRequiredVo> saveStepRequiredVos = processStepsMapper.selectJoinList(SaveStepRequiredVo.class, wrapper);

        // 构建按设备区分的工步所需参数映射
        return saveStepRequiredVos.stream()
                .collect(Collectors.groupingBy(SaveStepRequiredVo::getDeviceDistinguish,
                        Collectors.groupingBy(SaveStepRequiredVo::getStepId)));
    }


    /**
     * 准备 StepRequired 对象：遍历生产描述数据，
     * 根据工步和设备的对应关系，构建每个生产描述所需的参数对象 StepRequired 并保存。
     *
     * @param processDescriptions 生成的生产描述数据列表
     * @param stepRequiredMaps    按设备区分的工步所需参数映射
     * @return 需要保存的 StepRequired 对象列表
     */
    private List<StepRequired> prepareStepRequireds(List<ProcessDescription> processDescriptions, Map<String, Map<Long, List<SaveStepRequiredVo>>> stepRequiredMaps) {
        List<StepRequired> stepRequiredList = new ArrayList<>();

        // 遍历所有 ProcessDescription 对象
        for (ProcessDescription processDescription : processDescriptions) {
            // 遍历设备区分的映射
            stepRequiredMaps.values().forEach(stepRequiredMap -> {
                // 获取当前工步ID对应的参数列表
                List<SaveStepRequiredVo> requiredVos = stepRequiredMap.get(processDescription.getProcessStepsId());
                if (CollUtil.isNotEmpty(requiredVos)) {
                    // 构建并添加 StepRequired 对象
                    requiredVos.stream().map(saveStepRequiredVo -> {
                        StepRequired stepRequired = BeanUtil.copyProperties(saveStepRequiredVo, StepRequired.class);
                        stepRequired.setProcessDescriptionId(processDescription.getId());
                        return stepRequired;
                    }).forEach(stepRequiredList::add);
                }
            });
        }

        return stepRequiredList;
    }

    /**
     * 生产执行查询件号
     * @param automaticScheduleId
     * @return
     */
    @Override
    public List<PartNumberVo> getPartNumber(String automaticScheduleId) {
        //查询出相应件号
        List<ProcessDescription> processDescriptions1 = processDescriptionMapper.selectList(new LambdaQueryWrapper<ProcessDescription>()
                .eq(ProcessDescription::getAutomaticScheduleId, automaticScheduleId));

        List<PartNumberVo> collect1 = processDescriptions1.stream().map(processDescription -> {
            PartNumberVo partNumberVo = new PartNumberVo();
            partNumberVo.setPartNumber(processDescription.getPartNumber());
            partNumberVo.setProductStarter(processDescription.getState().equals(1L));
            return partNumberVo;
        }).collect(Collectors.toList());

        return collect1;
    }

    /**
     * 查询工艺描述
     *
     * @param automaticScheduleId
     * @return
     */
    @Override
    public List<ProcessSteps> getProcessDescription(String automaticScheduleId) {
        List<ProcessSteps> processSteps = processStepsMapper.selectList(new LambdaQueryWrapper<ProcessSteps>().eq(ProcessSteps::getProductionProcessesId, automaticScheduleId));
        return processSteps;
    }


    /***
     * "生产执行 查询工步所需
     * @param tpdId
     * @return
     */
    @Override
    public List<ProcessStepVo> getProcessStepDetails(Long tpdId) {
        List<ProcessStepVo> ProcessDescription=  processDescriptionMapper.getProcessStepDetails(tpdId);
        return ProcessDescription;
    }

    /**
     * 获取生产执行描述ID
     *
     * @param processDescriptionId
     * @return
     */
    @Override
    public List<ProcessDescription> getProcessDescriptionId(ProcessDescriptionIdDto processDescriptionId) {
        List<ProcessDescription> processDescription = processDescriptionMapper.selectList(new LambdaQueryWrapper<ProcessDescription>()
                .in(ProcessDescription::getProcessStepsId, processDescriptionId.getStepId())
                .eq(ProcessDescription::getPartNumber, processDescriptionId.getPartNumber())
                .eq(ProcessDescription::getAutomaticScheduleId, processDescriptionId.getAutomaticScheduleId()));
        return processDescription;
    }

    /**
     * 总装保存单件任务号
     *
     * @param updatePartNumberDto
     */
    @Override
    public void updatePartNumber(UpdatePartNumberDto updatePartNumberDto) {
        //获取全部的工步id
        List<ProcessDescription> processDescriptions = processDescriptionMapper.selectList(new LambdaQueryWrapper<ProcessDescription>()
                .eq(ProcessDescription::getAutomaticScheduleId, updatePartNumberDto.getAutomaticScheduleId())
                .in(ProcessDescription::getProcessStepsId, updatePartNumberDto.getStepId()));
        //去重、过滤件号不为空的，返回ID
        List<ProcessDescription> descriptions = new ArrayList<>(processDescriptions.stream()
                .filter(processDescription -> ObjectUtil.isEmpty(processDescription.getPartNumber()))
                .collect(Collectors.toMap(ProcessDescription::getProcessStepsId, Function.identity(), (o1, o2) -> o1))
                .values());
        //修改
        ProcessDescription processDescription = new ProcessDescription();
        processDescription.setPartNumber(updatePartNumberDto.getPartNumber());
        processDescriptionMapper.update(processDescription, new LambdaQueryWrapper<ProcessDescription>().in(ProcessDescription::getId, descriptions.stream().map(ProcessDescription::getId).collect(Collectors.toList())));
    }

    /**
     * 向下工位流转
     * <p>
     * planLineAutomaticMapper
     *
     * @param updateStaterDto
     */
    @Override
    public void updateProcessSteps(UpdateStaterDto updateStaterDto) {
        //总装
        if (updateStaterDto.getDeviceDistinguish().equals(ProduceEum.ASSEMBLY.getCode())) {
            //查询出 当前工序ID的下一个工序ID和 周部装组件拆分ID
            PlanLineAutomatic planLineAutomaticList =
                    planLineAutomaticMapper.selectOne(new LambdaQueryWrapper<PlanLineAutomatic>()
                            .eq(PlanLineAutomatic::getId, updateStaterDto.getAutomaticScheduleId()));

            if (Objects.isNull(planLineAutomaticList.getProcProcessIds())) {
                return;
            }
            //查询出当前主键
            PlanLineAutomatic planLineAutomatics = planLineAutomaticMapper.selectOne(new LambdaQueryWrapper<PlanLineAutomatic>()
                    .eq(PlanLineAutomatic::getProcProcessId, planLineAutomaticList.getProcProcessIds())
                    .eq(PlanLineAutomatic::getPlanLineAssembleBatchSplit, planLineAutomaticList.getPlanLineAssembleBatchSplit()));

            //根据主键修改任务状态
            PlanLineAutomatic planLineAutomatic = new PlanLineAutomatic();
            planLineAutomatic.setStaterNumber(ONE);
            planLineAutomaticMapper
                    .update(planLineAutomatic, new LambdaQueryWrapper<PlanLineAutomatic>().eq(PlanLineAutomatic::getId, planLineAutomatics.getId()));
        //部装
        } else if (updateStaterDto.getDeviceDistinguish().equals(ProduceEum.DIVISION.getCode())) {

            //查询出 当前工序ID的下一个工序ID和 周部装组件拆分ID
            PlanLineSchedule planLineAutomaticList =
                    planLineScheduleMapper.selectOne(new LambdaQueryWrapper<PlanLineSchedule>()
                            .eq(PlanLineSchedule::getId, updateStaterDto.getAutomaticScheduleId()));

            if (Objects.isNull(planLineAutomaticList.getProcProcessIds())) {
                return;
            }
            //查询出当前主键
            PlanLineSchedule planLineAutomatics = planLineScheduleMapper.selectOne(new LambdaQueryWrapper<PlanLineSchedule>()
                    .eq(PlanLineSchedule::getProcProcessId, planLineAutomaticList.getProcProcessIds())
                    .eq(PlanLineSchedule::getPlanLineAssembleSplitId, planLineAutomaticList.getPlanLineAssembleSplitId()));



            //根据主键修改任务状态
            PlanLineSchedule planLineAutomatic = new PlanLineSchedule();
            planLineAutomatic.setStaterNumber(ONE);
            planLineScheduleMapper
                    .update(planLineAutomatic, new LambdaQueryWrapper<PlanLineSchedule>().eq(PlanLineSchedule::getId, planLineAutomatics.getId()));

        }


    }


    /***
     *工步设备、工具参数数据矫正
     * @param gatherDto
     * @return
     */
    @Override
    public void addGather(GatherDto gatherDto) {

        //查询设备
        List<ResourceIdAndDeviceId> resource = processDescriptionMapper.selectResource(gatherDto.getStationId(), gatherDto.getDeviceId());
        if (CollUtil.isEmpty(resource)) {
            return;
        }
        //查询opc值
        LambdaQueryWrapper<DeviceConfigEntity> deviceConfigEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
        deviceConfigEntityLambdaQueryWrapper.in(DeviceConfigEntity::getDispositionId, gatherDto.getDispositionId());
        deviceConfigEntityLambdaQueryWrapper.in(DeviceConfigEntity::getResourceId, resource.stream().map(ResourceIdAndDeviceId::getResourceId).collect(Collectors.toList()));
        List<DeviceConfigEntity> deviceConfigEntities = deviceConfigMapper.selectList(deviceConfigEntityLambdaQueryWrapper);
        if (CollUtil.isEmpty(deviceConfigEntities)) {
            return;
        }
        Map<Long, List<DeviceConfigEntity>> deviceConfigEntityMap = deviceConfigEntities.stream().collect(Collectors.groupingBy(DeviceConfigEntity::getDispositionId));
        Map<Long, Long> map = resource.stream().collect(Collectors.toMap(ResourceIdAndDeviceId::getResourceId, ResourceIdAndDeviceId::getDeviceId));
        List<StepRequired> stepRequireds = stepRequiredService.list(Wrappers.<StepRequired>lambdaQuery()
                .in(StepRequired::getDeviceId, resource.stream().map(ResourceIdAndDeviceId::getDeviceId).collect(Collectors.toList()))
                .in(StepRequired::getStepsParameterId, deviceConfigEntities.stream().map(DeviceConfigEntity::getDispositionId).collect(Collectors.toList()))
                .in(StepRequired::getId, gatherDto.getTpdId()));
        stepRequireds.forEach(stepRequired -> {
            stepRequired.setCollectValue(deviceConfigEntityMap.get(stepRequired.getStepsParameterId())
                    .stream()
                    .filter(deviceConfigEntity -> map.get(deviceConfigEntity.getResourceId()).equals(stepRequired.getDeviceId()))
                    .collect(Collectors.toList()).get(0).getDCOpcName());
        });
        stepRequiredService.updateBatchById(stepRequireds);
    }

    /**
     * 生产执行 工步设备、工具参数数据矫正
     *
     * @param correctionDto
     */
    @Override
    public void addCorrection(CorrectionDto correctionDto) {
        StepRequired stepRequired = new StepRequired();
        stepRequired.setCollectValue(correctionDto.getCollectValue());
        stepRequiredService.update(stepRequired, new LambdaQueryWrapper<StepRequired>().in(StepRequired::getId, correctionDto.getProcessStepVoId()));
    }

    /**
     * 编写工步组执行：报工、取消报工
     *
     * @param deskCirculation
     */
    @Override
    public void deskCirculation(DeskCirculationDto deskCirculation) {
        ProcessDescription processDescription = new ProcessDescription();
        processDescription.setState(deskCirculation.getState());
        processDescriptionMapper.update(processDescription, new LambdaQueryWrapper<ProcessDescription>()
                .eq(ProcessDescription::getAutomaticScheduleId, deskCirculation.getAutomaticScheduleId())
                .eq(ProcessDescription::getProcessStepsId, deskCirculation.getProcessStepsId())
                .eq(ProcessDescription::getPartNumber, deskCirculation.getPartNumber()));

    }

    /**
     * 总装绑定产品编号
     *
     * @param bundleTheProductDto
     */
    @Override
    public void bundleTheProduct(List<BundleTheProductDto> bundleTheProductDto) {
        List<ProcessDescription> processDescriptions = new ArrayList<>();

        for (BundleTheProductDto theProductDto : bundleTheProductDto) {
            ProcessDescription processDescription = new ProcessDescription();
            processDescription.setProductNumber(theProductDto.getProductNumber());
            processDescription.setAutomaticScheduleId(theProductDto.getAutomaticScheduleId());
            processDescription.setPartNumber(theProductDto.getPartNumber());
            processDescription.setDistinguish("ASSEMBLY");

            processDescriptions.add(processDescription);
        }

        if (!processDescriptions.isEmpty()) {
            processDescriptionMapper.updateBatch(processDescriptions);
        }
    }
    /**
     * 烘烤记录
     * @param roastRecords
     */
    @Override
    public void roastRecords(RoastRecordsDto roastRecords) {
        ProcessDescription processDescription = new ProcessDescription();
        BeanUtils.copyProperties(roastRecords,processDescription);
        this.updateById(processDescription);
    }

    /**
     * 胶粘记录
     * @param glueRecordingDto
     */
    @Override
    public void glueRecords(GlueRecordingDto glueRecordingDto) {
        ProcessDescription processDescription = new ProcessDescription();
        BeanUtils.copyProperties(glueRecordingDto,processDescription);
        this.updateById(processDescription);
    }


}